//
//  DYZRandomColorController.m
//  DYZCars
//
//  Created by xmy on 16/8/20.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZRandomColorController.h"
#import "Masonry.h"
#import "UIColor+Addition.h"
#import "QuartzCore/QuartzCore.h"
#import "DYZChooseOutColorController.h"
#import "DYZChooseInColorController.h"
#import "DYZCardCityController.h"
#import "DYZEffectDateController.h"
#import "DYZSearchCarsController.h"



@interface DYZRandomColorController ()
@property(nonatomic,weak)UITextField *textFiled;

@end

@implementation DYZRandomColorController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //右侧保存按钮
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveClick)];
    self.navigationItem.rightBarButtonItem = item;
    
    [self leftButton];
    [self setupUI];

}

//左侧返回按钮
- (void)leftButton{
    //左侧返回按钮
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    // 为返回按钮设置图片样式
    [button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    //按钮的点击事件
    [button addTarget:self action:@selector(popController) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = backButton;
    
    //将返回按钮的文字position设置不在屏幕上显示
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
}
//左侧按钮点击事件
- (void)popController{
    
    [self.navigationController popViewControllerAnimated:YES];
}

//保存按钮事件
- (void)saveClick{
    
    //跳转到寻车详情
   if (self.flag == 0) {
       
    DYZChooseOutColorController *outC = [[DYZChooseOutColorController alloc]init];
       outC.outcolorData = self.textFiled.text;
       
       
       [self.navigationController pushViewController:outC animated:YES];
       
   }else if(self.flag == 1)
   {
       DYZChooseInColorController *vc = [[DYZChooseInColorController alloc]init];
       
       vc.incolor = self.textFiled.text;
       
       //使用通知传值
       NSDictionary *dict = @{@"title":vc.resultColor};
       [[NSNotificationCenter defaultCenter] postNotificationName:@"random" object:nil userInfo:dict];
       
       [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
       
   }else if(self.flag == 2)
   {
       DYZCardCityController *Ct = [[DYZCardCityController alloc]init];
       
       [self.navigationController pushViewController:Ct animated:YES];
       
   }else if(self.flag == 3)
   {
       DYZEffectDateController *DC = [[DYZEffectDateController alloc]init];
       
       [self.navigationController pushViewController:DC animated:YES];
       
   }
        
    
}

- (void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITextField *text = [[UITextField alloc]init];
    
    UIView *view = [[UIView alloc]init];
    
    [self.view addSubview:view];
    
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"input-1"]];
    
    self.textFiled.text = text.text;
    
    [view addSubview:text];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(74);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.offset(45);
    }];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(view);
        make.left.equalTo(view).offset(10);
        make.right.equalTo(view).offset(-10);
       
    }];

    switch (self.flag) {
        case 0:
            text.placeholder = @"请输入颜色";
            self.navigationItem.title = @"自定义外观颜色";
            break;
            
        case 1:
            text.placeholder = @"请输入颜色";
            self.navigationItem.title = @"自定义内饰颜色";
            break;
        case 2:
            text.placeholder = @"请输入区域";
            self.navigationItem.title = @"自定义区域";
            break;
        case 3:
            text.placeholder = @"请输入有效期";
            self.navigationItem.title = @"自定义有效期";
            break;
            
        default:
            break;
    }
    
}

@end
